﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufInterface.h"

namespace gnuf
{
    // see https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox
    enum MsgBoardType
    {
        // buttons
        eMB_OK = 0x00000000L,
        eMB_OKCANCEL = 0x00000001L,
        eMB_ABORTRETRYIGNORE = 0x00000002L,
        eMB_YESNOCANCEL = 0x00000003L,
        eMB_YESNO = 0x00000004L,
        eMB_RETRYCANCEL = 0x00000005L,
        eMB_SAVENOTSAVECANCEL = 0x00000006L,

        // icons
        eMB_ICONASTERISK = 0x00000000L,
        eMB_ICONHAND = 0x00000010L,
        eMB_ICONWARNINGINFO = 0x00000020L,
        eMB_ICONEXCLAMATION = 0x00000030L,
        eMB_ICONLOWWARNING = 0x00000040L,
        eMB_ICONSUCCESS = 0x00000050L,
        eMB_ICONWARNING = eMB_ICONEXCLAMATION,
        eMB_ICONERROR = eMB_ICONHAND,
        eMB_ICONINFORMATION = eMB_ICONASTERISK,
        eMB_ICONSTOP = eMB_ICONHAND,

        // defaultButton
        eMB_DEFBUTTON1 = 0x00000000L,
        eMB_DEFBUTTON2 = 0x00000100L,
        eMB_DEFBUTTON3 = 0x00000200L,
        eMB_DEFBUTTON4 = 0x00000300L
    };

    enum class MsgBoardReturnValue
    {
        eIDFATAL = -1,  // 一般情况下，不会返回这个值，一旦返回，请立即排查或弹DBG_WARN
        eIDOK = 1,
        eIDCANCEL,
        eIDABORT,
        eIDRETRY,
        eIDIGNORE,
        eIDYES,
        eIDNO,
        eIDSAVE,
        eIDNOTSAVE,
        eIDCLOSE = -2
    };
    
    // see https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-msgboxparamsa
    // it is a simplified version of MSGBOXPARAMS
    struct MsgBoardParams
    {
        struct { int width; int height; } cbSize = { -1, - 1 }; // fixSize值，-1代表了自适应
        unsigned long long owner = 0; // HWND(for ms window) or winId(for qt widget)
        std::wstring text;
        std::wstring auxiliary;
        std::wstring caption;
        std::wstring iconDir;
        std::wstring buttons[4]; // 最多4个按钮
        int defaultBtn = 0; // 默认按钮
        bool withCloseButton = false;
        bool* pWantToIgnore = nullptr;
    };

    class GNUF_INTERFACE_EXPORT MessageBoardInterface
    {
    public:
        static MessageBoardInterface* Get();

    public:
        // see https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messageboxindirecta
        virtual int ShowMessageBoardIndirect(MsgBoardParams&) = 0;

    protected:
        MessageBoardInterface() {}

        // 此接口由UI框架调用，外部不可调用。
        // 如必须调用，请联系jianggy-a@glodon.com
        void SetInterface(MessageBoardInterface*);

    private:
        MessageBoardInterface(const MessageBoardInterface&) = delete;
        MessageBoardInterface(MessageBoardInterface&&) = delete;
        MessageBoardInterface& operator=(const MessageBoardInterface&) = delete;
    };

    // see https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox
    // \brief pWantToIgnore:MessageBoard左下角是否显示“不再提示”，pWantToIgnore仍作为是否勾选“不再提示”的结果值
    GNUF_INTERFACE_EXPORT MsgBoardReturnValue ShowMessageBoard(const std::wstring& text, const std::wstring& caption, int type = eMB_OK, bool* pWantToIgnore = nullptr);
    GNUF_INTERFACE_EXPORT MsgBoardReturnValue ShowMessageBoard(unsigned long long winId, const std::wstring& text, const std::wstring& caption, int type = eMB_OK, bool* pWantToIgnore = nullptr);
    GNUF_INTERFACE_EXPORT MsgBoardReturnValue ShowMessageBoard(const std::wstring& text, const std::wstring& caption, bool withCloseBtn, int type = eMB_OK, bool* pWantToIgnore = nullptr);
    GNUF_INTERFACE_EXPORT MsgBoardReturnValue ShowMessageBoard(unsigned long long winId, const std::wstring& text, const std::wstring& caption, bool withCloseBtn, int type = eMB_OK, bool* pWantToIgnore = nullptr);
    GNUF_INTERFACE_EXPORT int ShowMessageBoardIndirect(MsgBoardParams& msgboardParams);
}
